﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Rainy.FrameWork;
using System.Data;

namespace Admin.Sys.PetBreed
{
    public partial class PetBreed_List : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                LoadListData();
            }
        }

        /// <summary>
        /// 列表数据加载
        /// </summary>
        private void LoadListData()
        {
            pagingControl.OnlyField = "SYS_PETBREED_ID";                 //主ID
            pagingControl.OrderSyntax = " ORDER BY CREATE_TIME desc";   //排序条件
            pagingControl.TableName = "T_SYS_PETBREED";                  //表名：T_PET_REGINFO（注册信息表）
            pagingControl.InstanceName = WebConfig.DataInstance;
            pagingControl.ProcedureName = "COMMON_PAGING";              //分页（存储过程）
            pagingControl.Condition = GetCondition();                   //查询条件

            DataTable dt = pagingControl.GetDataSet().Tables[0];
            this.gvInfo.DataSource = dt;
            this.gvInfo.DataBind();
        }

        /// <summary>
        /// 查询条件
        /// </summary>
        /// <returns></returns>
        private string GetCondition()
        {
            string condition = "1=1";

            //品种名称
            if (!string.IsNullOrEmpty(this.txtName.Value.Trim()))
            {
                condition += " AND NAME= '%" + this.txtName.Value.Trim() + "%'";
            }
            //助记码
            if (!string.IsNullOrEmpty(this.txtHelpCode.Value.Trim()))
            {
                condition += " AND HELP_CODE='%" + txtHelpCode.Value.Trim() + "%'";
            }
            //个人一般区限养
            if (!string.IsNullOrEmpty(this.ddlPerCom.SelectedItem.Value))
            {
                condition += " AND LIMIT_PER_COM='" + ddlOrgCom.SelectedItem.Value + "'";
            }
            //单位一般区限养
            if (!string.IsNullOrEmpty(this.ddlOrgCom.SelectedItem.Value))
            {
                condition += " AND LIMIT_ORG_COM='" + ddlPerCom.SelectedItem.Value + "'";
            }
            //个人重点区限养
            if (!string.IsNullOrEmpty(this.ddlPerImp.SelectedItem.Value))
            {
                condition += " AND LIMIT_PER_IMP='" + ddlPerImp.SelectedItem.Value + "'";
            }
            //单位重点区限养
            if (!string.IsNullOrEmpty(this.ddlOrgIMP.SelectedItem.Value))
            {
                condition += " AND LIMIT_ORG_IMP='" + ddlOrgIMP.SelectedItem.Value + "'";
            }
            //个人其他区限养
            if (!string.IsNullOrEmpty(this.ddlPerOther.SelectedItem.Value))
            {
                condition += " AND LIMIT_PER_OTHER='" + ddlPerOther.SelectedItem.Value + "'";
            }
            //单位其他区限养
            if (!string.IsNullOrEmpty(this.ddlOrgOther.SelectedItem.Value))
            {
                condition += " AND LIMIT_ORG_OTHER='" + ddlOrgOther.SelectedItem.Value + "'";
            }
            return condition;
        }

        /// <summary>
        /// 分页事件
        /// </summary>
        protected void pagingControl_PageChanged()
        {
            LoadListData();
        }

        /// <summary>
        /// 查询事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            LoadListData();
        }
    }
}